package com.sto.stoapp.activity.aviation;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.util.UnifiedStaticType;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

public class StoAviTwentyFourHoursActivity extends StoHomeActivity {

    // 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.send_piece_by_route,
            R.string.bag_and_send_piece, R.string.send_bag, R.string.arrived_piece };

    private ListView hoursList;

    private SoleAdapter soleAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sto_sales_received_piece);
        this.setTitleBottom(R.string.h_received_piece,
                HomeBroadAction.AVIATION_SCANNER_BROAD);
        initWidget();

    }

    private void initWidget() {
        hoursList = (ListView) findViewById(R.id.receivedFunc_list);
        soleAdapter = new SoleAdapter(this, getResourceList());
        hoursList.setAdapter(soleAdapter);
        hoursList.setOnItemClickListener(new StoOnItemClickListener(this) {

            @Override
            public void KcOnItemClickListener(AdapterView<?> parent, View view,
                    int position, long id) {
                view.setSelected(true);
                TextView title = (TextView) view.findViewById(R.id.res_test);
                clickItemEvent(title.getText().toString());

            }
        });

    }

    private void clickItemEvent(String title) {
        // 航空-扫描员-指定路由号发件
        if (title.equals(getText(R.string.send_piece_by_route))) {
            Intent intent = new Intent(this, StoSendPieceByRouteActivity.class);
            //          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 航空-扫描员-装包&发件
        else if (title.equals(getText(R.string.bag_and_send_piece))) {
            Intent intent = new Intent(this, StoBagAndSendActivity.class);
            //          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 航空-扫描员-发包
        else if (title.equals(getText(R.string.send_bag))) {
            Intent intent = new Intent(this, StoAviSendBagActivity.class);
            //          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
        // 航空-扫描员-到件
        else if (title.equals(getText(R.string.arrived_piece))) {
            Intent intent = new Intent(this,
                    StoAviationToPieceActivity.class);
            //          intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra(UnifiedStaticType.IS_24HOURS, true);
            startActivity(intent);
        }
    }

    private List<FunctionEntity> getResourceList() {
        List<String> resList = new ArrayList<String>();
        resList.add(getText(R.string.send_piece_by_route).toString());
        resList.add(getText(R.string.bag_and_send_piece).toString());
        resList.add(getText(R.string.send_bag).toString());
        resList.add(getText(R.string.arrived_piece).toString());

        List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
        for (String res : resList) {
            FunctionEntity entity = new FunctionEntity();
            entity.setTitle(res);
            functionList.add(entity);
        }
        return functionList;
    }




}
